package {{project.group}}.{{project.artifact}};

import org.apache.log4j.Logger;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.json.Json;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;

@Path("/")
public class AppController extends Controller {

	private static Logger logger = Logger.getLogger(AppController.class);

	public <T> T getJson(Class<T> jsonClass) {
		String raw = getRawData();
		return Json.getJson().parse(raw, jsonClass);
	}

	/**
	 * http :8000
	 */
	public void index() {
		renderText("Hello JFinal World.");
	}
	
	/**
	 * http :8000/json hello=world
	 */
	public void json() {
		Ret ret= getJson(Ret.class);
		renderJson(ret);
	}

	/**
	 * http :8000/download file=file.zip > file2.zip
	 */
	public void download() {
		String file = getPara("file");
		renderFile(file);
	}

	/**
	 * http -f POST :8000/upload cv@file2.zip
	 */
	public void upload() {
		UploadFile file = getFile("cv");
		logger.error(file);
		renderText("upload ok!");
	}

}